package com.watson.minio.springminio.minio.controller;

import com.watson.minio.springminio.minio.util.MinioUtil;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * // todo
 *
 * @author: llun
 * @date: 2022/1/24 10:30
 * @version: 1.0
 */
@RestController
@Api(tags ="minio文件上传")
@RequestMapping("minio")
public class MinioController {
    private final Logger logger = LoggerFactory.getLogger(MinioController.class);
    @Autowired(required = false)
    MinioUtil minioUtil;

    @GetMapping("upload")
    public String uploadFile(@RequestParam MultipartFile file) {
        return minioUtil.uploadFile(file);
    }

    @GetMapping("getFileUrl")
    public String getFileUrl(@RequestParam String fileName) {
        return minioUtil.getFileUrl(fileName);
    }

    @GetMapping("download")
    public void downloadFile(@RequestParam String fid,
                             @RequestParam String fileName,
                             HttpServletRequest req, HttpServletResponse res) {
        minioUtil.lookUploadFile(req, res, fid, fileName);
        logger.info("下载文件完成");
    }


}
